﻿using System.Collections.Generic;
using UnityEngine;

public struct AddScreenplayInfo
{
    ///<summary>
    ///Screenplay的model，这里当然可以从数据里拿，也可以是逻辑脚本现生成的
    ///</summary>
    public string ScreenplayId;
    ///<summary>
    ///剩余多久，单位：回合
    ///</summary>
    public int Duration;
    ///<summary>
    ///是否是一个永久的剧本，即便=true，时间设置也是有意义的，因为时间如果被减少到0以下，即使是永久的也会被删除
    ///</summary>
    public bool Permanent;
    
    public AddScreenplayInfo(
        string screenplayId,int duration,
        bool permanent = false
    ){
        this.ScreenplayId = screenplayId;
        this.Duration = duration;
        this.Permanent = permanent;
    } 
}

public class ScreenplayObj
{
    ///<summary>
    ///这是个什么Screenplay
    ///</summary>
    public ScreenplayModel Model;

    ///<summary>
    ///剩余多久，单位：回合
    ///</summary>
    public int Duration;

    ///<summary>
    ///是否是一个永久的Screenplay，永久的duration不会减少，但是timeElapsed还会增加
    ///</summary>
    public bool Permanent;

    ///<summary>
    ///Screenplay已经存在了多少时间了，单位：回合
    ///</summary>
    public int TimeElapsed = 0;

    ///<summary>
    ///Screenplay执行了多少次onTick了，如果不会执行onTick，那将永远是0
    ///</summary>
    public int Ticked = 0;

    ///<summary>
    ///Screenplay的一些参数，这些参数是逻辑使用的，比如wow中牧师的盾还能吸收多少伤害，就可以记录在buffParam里面
    ///</summary>
    public Dictionary<string, object> ScreenplayParam = new Dictionary<string, object>();

    public ScreenplayObj(
        ScreenplayModel model,  int duration, bool permanent = false,
        Dictionary<string, object> screenplayParam = null
    ){
        this.Model = model;
        this.Duration = duration;
        this.Permanent = permanent;
        if (screenplayParam != null) {
            foreach(KeyValuePair<string, object> kv in screenplayParam){
                this.ScreenplayParam.Add(kv.Key, kv.Value);
            }
        }
    } 
}

public struct ScreenplayModel
{
    ///<summary>
    ///剧本的id
    ///</summary>
    public string Id;

    ///<summary>
    ///剧本的名称
    ///</summary>
    public string Name;

    ///<summary>
    ///剧本的优先级，优先级越低的剧本越后面执行
    ///</summary>
    public int Priority;

    ///<summary>
    ///剧本在每个总回合时要做的事情
    ///</summary>
    public ScreenplayOnRoundTick OnRoundTick;
    public object[] OnRoundTickParams;

    ///<summary>
    ///剧本在每单个阵营回合时要做的事情
    ///</summary>
    public ScreenplayOnCompRoundTick OnCompRoundTick;
    public object[] OnCompRoundTickParams;

    ///<summary>
    ///剧本在某个棋子执行某个操作时要做的事情
    ///</summary>
    public ScreenplayOnActionPawn OnActionPawn;
    public object[] OnActionPawnParams;

    ///<summary>
    ///剧本在某个棋子被击杀时要做的事情
    ///<param name="buff">会传递给脚本buffObj作为参数</param>
    ///<param name="damageInfo">这次的伤害信息</param>
    ///<param name="target">挨打的角色对象</param>
    ///</summary>
    public ScreenplayOnKillPawn OnKillPawn;
    public object[] OnKillPawnParams;

    public ScreenplayModel(
        string id, string name, int priority,
        string onRoundTick, object[] roundTickParam,
        string onCompRoundTick, object[] compRoundTickParams,
        string onActionPawn, object[] actionPawnParams,
        string OnKillPawn, object[] KillPawnParams
    ){
        this.Id = id;
        this.Name = name;
        this.Priority = priority;
        this.OnRoundTick = (onRoundTick == "") ? null : DesignerScripts.Screenplay.OnRoundTickFunc[onRoundTick];
        this.OnRoundTickParams = roundTickParam;
        this.OnCompRoundTick = (onCompRoundTick == "") ? null : DesignerScripts.Screenplay.OnCompRoundTickFunc[onCompRoundTick];
        this.OnCompRoundTickParams = compRoundTickParams;
        this.OnActionPawn = (onActionPawn == "") ? null : DesignerScripts.Screenplay.OnActionPawnFunc[onActionPawn];
        this.OnActionPawnParams = actionPawnParams;
        this.OnKillPawn = (OnKillPawn == "") ? null : DesignerScripts.Screenplay.OnKillPawnFunc[OnKillPawn];
        this.OnKillPawnParams = KillPawnParams;
    }
}

/// <summary>
/// 总回合增加时
/// </summary>
public delegate void ScreenplayOnRoundTick(ScreenplayObj  screenplay);

/// <summary>
/// 某个阵营增加回合时
/// </summary>
public delegate void ScreenplayOnCompRoundTick(ScreenplayObj screenplay);

/// <summary>
/// 棋子进行某个操作时
/// </summary>
public delegate void ScreenplayOnActionPawn(ScreenplayObj screenplay);
/// <summary>
/// 棋子被击杀时
/// </summary>
public delegate void ScreenplayOnKillPawn(ScreenplayObj screenplay);